#include "comfunc.h"


uint16_t sp_crc16_with_init(uint16_t crc, const uint8_t *buf, uint16_t size)
{
    unsigned char i;

    while (size-- != 0)
    {
        for (i = 0x80; i != 0; i >>= 1)
        {
            if ((crc & 0x8000) != 0)
            {
                crc <<= 1;
                crc ^= 0x1021;
            }
            else
            {
                crc <<= 1;
            }
            if (((*buf) & i) != 0)
            {
                crc ^= 0x1021;
            }
        }
        buf++;
    }
    return (crc);
}
